﻿Namespace EyeOpen.Toolbar.Windows

    Partial Public Class MainForm
        Inherits Form
        Public Sub New()
            InitializeComponent()

            Dim buttons = GetButtonList()

            For Each toolStripButton In buttons
                toolStrip1.Items.Add(toolStripButton)
            Next toolStripButton
        End Sub

        Private Sub Edit()
            MessageBox.Show("Edit")
        End Sub

        Private Sub Save()
            MessageBox.Show("Save")
        End Sub

        Private Function GetButtonList() As IEnumerable(Of ToolStripButton)
            Dim buttonList As New List(Of ToolStripButton)
            buttonList.Add(CreateButton("Edit", AddressOf Edit))
            buttonList.Add(CreateButton("Save", AddressOf Save))

            Return buttonList
        End Function

        Private Function CreateButton(ByVal text As String, ByVal action As Action) As ToolStripButton
            Dim button = New ToolStripButton(text)

            AddHandler button.Click, Sub(s, e) action()

            Return button
        End Function
    End Class
End Namespace